<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
        required 定义内容不能为空
    -->
    <input type="text" required pattern="[0-9]" name="" id="">
    <input type="button" value="点击" name="" id="">
    <script>
        // 正则:为了验证字符串
        var but = document.querySelector("[type=button]");
        var inp = document.querySelector("[type=text]");
        // [] 表示一个字符条件
        // ^ 以谁为开头
        // /d === [0-9]
        // {3} 大括号之前的条件出现3次
        // {3,6} 大括号之前的条件最少出现3次最多出现6次
        var reg = /\w./i;
        var reg1 = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        but.onclick = function(){
            var val = inp.value;
            console.log(val);
            var boo = reg.test(val);
            console.log(boo);
        }
    </script>
</body>
</html>